n = int(input())
n_1 = n % 10
n_2 = (n // 10) % 10
n_3 = (n % 10) // 10
n_4 = n // 1000
for i in range(n):
    if (n_1 + n_2) % 2 != 0 and (n_1 + n_2) % 3 != 0 and (n_1 + n_2) % 5 != 0:
        print(n_1 + n_2)
    else:
        print("0")
    if (n_1 + n_3) % 2 != 0 and (n_1 + n_3) % 3 != 0 and (n_1 + n_3) % 5 != 0:
        print(n_1 + n_3)
    else:
        print("0")

    if (n_1 + n_4) % 2 != 0 and (n_1 + n_4) % 3 != 0 and (n_1 + n_4) % 5 != 0:
        print(n_1 + n_3)
    else:
        print("0")

    if (n_2 + n_3) % 2 != 0 and (n_2 + n_3) % 3 != 0 and (n_2 + n_3) % 5 != 0:
        print(n_2 + n_3)
    else:
        print("0")
    if (n_2 + n_4) % 2 != 0 and (n_2 + n_4) % 3 != 0 and (n_2 + n_4) % 5 != 0:
        print(n_1 + n_4)
    else:
        print("0")

    if (n_3 + n_4) % 2 != 0 and (n_3 + n_4) % 3 != 0 and (n_3 + n_4) % 5 != 0:
        print(n_3 + n_4)
    else:
        print("0")